using System;
using System.Collections;

namespace Scenario.Modules.DM.DataBase
{
	public class DocumentCounter 
	{
		private const string sFile = "DocumentCounter.db";

		private bOSdotNET.DB.Counter counter = null;
		private ArrayList counters = new ArrayList();

		public DocumentCounter(string sDocumentPath) 
		{
			counter = new bOSdotNET.DB.Counter(sDocumentPath + sFile);
			counters.Add(counter);
		}

		public DocumentCounter(string sDocumentPath, string sDocumentFile) 
		{
			counter = new bOSdotNET.DB.Counter(sDocumentPath + sDocumentFile + ".db");
			counters.Add(counter);
		}

		public long Increment()
		{
			return counter.Increment();
		}

		public long Increment(string sDocumentPath, string sDocument)
		{
			string sCounterFile = sDocumentPath + sDocument + ".db";
			bOSdotNET.DB.Counter myCounter = this.GetCounter (sCounterFile);

			return myCounter.Increment();
		}

		public long Increment(string sDocumentPath)
		{
			string sCounterFile = sDocumentPath + sFile;
			bOSdotNET.DB.Counter myCounter = this.GetCounter (sCounterFile);

			return myCounter.Increment();
		}

		private bOSdotNET.DB.Counter GetCounter(string sDBFile)
		{
			bOSdotNET.DB.Counter myCounter = null;

			for ( int i=0; i<counters.Count;i++)
			{
				myCounter = (bOSdotNET.DB.Counter)counters[i];

				if ( counter.FileName.CompareTo (sDBFile) == 0) 
				{
					return counter;
				}
			}

			myCounter = new bOSdotNET.DB.Counter(sDBFile);

			counters.Add(myCounter);

			return myCounter ;
		}
	}
}
